package oj0320.oj0320_01;
import java.util.Scanner;

class Node {
    int data;
    Node next;

    Node(int data) {
        this.data = data;
        this.next = null;
    }
}

class LinkList {
    private Node first;

    public LinkList() {
        first = new Node(0); // 头结点
        first.next = null;
    }

    public LinkList(int[] a) {
        first = new Node(0); // 头结点
        Node r = first;
        for (int value : a) {
            Node s = new Node(value);
            r.next = s;
            r = s;
        }
        r.next = null;
    }

    //删除链表中重复的数字
    public void deleteDuplicates() {
        //编写满足题目要求的代码
        Node p = first.next;    //引用p
        while (p != null && p.next != null) {
            if (p.data == p.next.data){
                p.next = p.next.next;
            }else {
                p = p.next;
            }
        }
    }

    //输出链表元素的值
    public void display() {
        Node p = first.next;
        if (p == null) {
            return;
        }
        while (p.next != null) {
            System.out.print(p.data + "->");
            p = p.next;
        }
        System.out.println(p.data);
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        LinkList link = new LinkList(a);//初始化一个链表
        link.deleteDuplicates();//调用去重方法
        link.display();//输出链表
        scanner.close();
    }
}